<?php

namespace App\Repositories\Eloquent;

use Prettus\Repository\Eloquent\BaseRepository;
use Prettus\Repository\Criteria\RequestCriteria;
use App\Repositories\Contract\ProjectRepository;
use App\Models\Project;
use App\Validators\ProjectValidator;
use App\Table\Constant\Project as CProject;

/**
 * Class ProjectRepositoryEloquent.
 *
 * @package namespace App\Repositories\Eloquent;
 */
class ProjectRepositoryEloquent extends BaseRepository implements ProjectRepository
{
    /**
     * Specify Model class name
     *
     * @return string
     */
    public function model()
    {
        return Project::class;
    }

    /**
     * @inheritDoc
     */
    public function copy(Project $project, int $userId): Project
    {
        $payload = $project->only([
            'title',
        ]);
        $payload['status'] = CProject::STATUS_NORMAL;
        $payload['template'] = CProject::TEMPLATE_NO;
        $payload['system'] = CProject::SYSTEM_NO;
        $payload['user_id'] = $userId;
        return $this->create($payload);
    }


    /**
     * Boot up the repository, pushing criteria
     */
    public function boot()
    {
        $this->pushCriteria(app(RequestCriteria::class));
    }
    
}
